﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;

namespace ACM
{
    public static class UIHelper
    {
        public static DateTime GetDateFromUI(string txt)
        {
            if (txt.Contains("-") || txt.Contains("/"))
            {
                //return DateTime.Parse(txt);
                string[] dt = txt.Split(new Char[] { '-', '/' });
                int TimeZoneDiff = Convert.ToInt32(ConfigurationManager.AppSettings["TimeZoneDiff"].ToString());
                return new DateTime((Convert.ToInt16(dt[2]) > DateTime.Now.AddHours(TimeZoneDiff).Year + 100 ? Convert.ToInt16(dt[2]) - 543 : Convert.ToInt16(dt[2])), Convert.ToInt16(dt[1]), Convert.ToInt16(dt[0]));
            }

            return new DateTime();
        }

        public static string GetDateStringFromUI(string txt)
        {
            if (txt.Contains("-"))
            {
                string[] dt = txt.Split('-');
                int buddestYear = Convert.ToInt16(dt[2]) - 543;
                if (buddestYear < 1900)
                    buddestYear += 543;
                return "'" + buddestYear.ToString() + dt[1] + dt[0] + "'";
            }

            return "NULL";
        }
    }
}